package com.demo8.basic.enums;

import com.demo8.basic.enums.base.BaseEnum;

import java.util.Arrays;

public enum BizCodeEnum implements BaseEnum {
    SUCCESS(200, "请求成功！"),
    SYSTEM_ERROR(-1, "系统异常！"),
    BIZ_FAILED(1000, "请求异常,请稍后重试！"),
    NOT_FOUND_USER(1001, "没有这个用户"),
    NOT_FOUND_DEPT(1002, "没有这个部门"),
    NOT_CORRECT_ID(1003, "错误的id"),
    DUPLICATE_DEPT_NAME(1004, "部门名称重复"),
    DUPLICATE_ROLE_NAME(1005, "角色名称重复"),
    DUPLICATE_ROLE_CODE(1006, "权限编码重复"),
    LOGIN_FAILED(2000, "登录失败,用户名或密码错误或您的账号已被关闭"),
    NOT_CONFIRMED_PASSWORD(2001, "修改失败！两次密码不一致"),
    NOT_CURRENT_PASSWORD(2002, "修改失败！原密码不正确或用户不存在"),
    UNAUTHORIZED(2003, "登录失效，请重新登录"),
    NULL_TOKEN(2004, "token不能为空"),
    DUPLICATE_USER_NAME(2005, "用户名重复"),
    DUPLICATE_MOBILE(2006, "手机号重复"),
    NO_PERMISSION(2007, "没有操作权限"),
    DUPLICATE_CONFIG_NAME(3001, "配置名重复"),
    DUPLICATE_DICT_TYPE(4001, "字典类型重复"),
    DUPLICATE_MENU_NAME(4002, "菜单名称重复"),
    DUPLICATE_POST_NAME(4003, "岗位名称重复"),
    DUPLICATE_POST_CODE(4004, "岗位编码重复"),
    DUPLICATE_DICT_TYPE_VALUE(4005, "字典值重复"),
    UNKNOWN_DATA_SOURCE_TYPE(5001, "未知的数据库类型"),
    FILE_IS_TOO_LARGE(6001, "文件超出限定大小"),
    FILE_NAME_IS_NOT_EMPTY(6002, "文件名称不可为空"),
    FILE_NAME_OUT_OF_LINE(6003, "文件名称过长"),
    UPLOAD_FAILED(6004, "上传失败"),
    INCORRECT_FILE_TYPE(6005, "文件类型异常"),
    FILE_NOT_EXISTS(6006, "文件不存在");

    private Integer code;
    private String msg;

    private BizCodeEnum(Integer value, String msg) {
        this.code = value;
        this.msg = msg;
    }

    public static BizCodeEnum of(int code) {
        return Arrays.stream(values()).filter((bizCodeEnum) -> bizCodeEnum.code.equals(code)).findFirst().orElse(BIZ_FAILED);
    }

    @Override
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}